﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Query2Object
{
    public class Exp
    {
        private string ColumnName;
        private string _Query;
        public String Query
        {
            get
            {
                return _Query;
            }
        }
        public String Name
        {
            get { return ColumnName; }
        }
        public Exp(string Column)
        {
            ColumnName = Column;
        }

        //等于操作开始
        public Exp EqulesExp(string Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " = '" + Value + "' ";
            return rs;
        }
        public Exp EqulesExp(int Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " = " + Value + " ";
            return rs;
        }
        public Exp EqulesExp(long Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " = " + Value + " ";
            return rs;
        }
        public Exp EqulesExp(DateTime Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " = '" + Value.ToString() + "' ";
            return rs;
        }
        public Exp EqulesExp()
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " = @" + ColumnName + " ";
            return rs;
        }
        //等于操作结束

        //不等于操作开始
        public Exp NotEquls(string Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " <> '" + Value + "' ";
            return rs;
        }
        public Exp NotEquls(int Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " <> " + Value + " ";
            return rs;
        }
        public Exp NotEquls(long Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " <> " + Value + " ";
            return rs;
        }
        public Exp NotEquls(DateTime Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " <> '" + Value.ToString() + "' ";
            return rs;
        }
        public Exp NotEquls()
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " <> @" + ColumnName + " ";
            return rs;
        }
        //不等于操作结束
        //大于操作开始
        public Exp MoreThan(string Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " > '" + Value + "' ";
            return rs;
        }
        public Exp MoreThan(int Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " > " + Value + " ";
            return rs;
        }
        public Exp MoreThan(long Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " > " + Value + " ";
            return rs;
        }
        public Exp MoreThan(DateTime Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " > '" + Value.ToString() + "' ";
            return rs;
        }
        public Exp MoreThan()
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " > @" + ColumnName + " ";
            return rs;
        }
        //大于操作结束

        //小于操作开始
        public Exp LessThan(string Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " < '" + Value + "' ";
            return rs;
        }
        public Exp LessThan(int Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " < " + Value + " ";
            return rs;
        }
        public Exp LessThan(long Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " < " + Value + " ";
            return rs;
        }
        public Exp LessThan(DateTime Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " < '" + Value.ToString() + "' ";
            return rs;
        }
        public Exp LessThan()
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " < @" + ColumnName + " ";
            return rs;
        }
        //小于操作结束

        //小于等于操作开始
        public Exp LessEqules(string Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " <= '" + Value + "' ";
            return rs;
        }
        public Exp LessEqules(int Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " <= " + Value + " ";
            return rs;
        }
        public Exp LessEqules(long Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " <= " + Value + " ";
            return rs;
        }
        public Exp LessEqules(DateTime Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " <= '" + Value.ToString() + "' ";
            return rs;
        }
        public Exp LessEqules()
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " <= @" + ColumnName + " ";
            return rs;
        }
        //小于等于操作结束

        //大于等于操作开始
        public Exp MoreEqules(string Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " >= '" + Value + "' ";
            return rs;
        }
        public Exp MoreEqules(int Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " >= " + Value + " ";
            return rs;
        }
        public Exp MoreEqules(long Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " >= " + Value + " ";
            return rs;
        }
        public Exp MoreEqules(DateTime Value)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " >= '" + Value.ToString() + "' ";
            return rs;
        }
        public Exp MoreEqules()
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += ColumnName + " >= @" + ColumnName + " ";
            return rs;
        }
        //大于等于操作结束
        //在两个数值之间开始
        public Exp Between(string p1, string p2)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += "(" + ColumnName + " between '" + p1 + "' AND '" + p2 + "') ";
            return rs;
        }
        public Exp Between(int p1, int p2)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += "(" + ColumnName + " between " + p1 + " AND " + p2 + ") ";
            return rs;
        }
        public Exp Between(long p1, long p2)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += "(" + ColumnName + " between " + p1 + " AND " + p2 + ") ";
            return rs;
        }
        public Exp Between(DateTime p1, DateTime p2)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += "(" + ColumnName + " between '" + p1.ToString() + "' AND '" + p2.ToString() + "') ";
            return rs;
        }
        //在两个数值之间结束
        public Exp DateBetween(DateTime p1, DateTime p2)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += "(datediff(day,'" + p1.Date.ToShortDateString() + "'," + ColumnName + ")>=0 And datediff(day," + ColumnName + ",'" + p2.Date.ToShortDateString() + "',)>=0) ";
            return rs;
        }
        public Exp In(List<string> range)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += "("+ColumnName + " In (";
            foreach (string item in range)
            {
                rs._Query += "'" + item + "',";
            }
            rs._Query = rs._Query.Remove(rs._Query.Length - 1) + "))";
            return rs;
        }
        public Exp In(List<int> range)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += "(" + ColumnName + " In (";
            foreach (int item in range)
            {
                rs._Query += item + ",";
            }
            rs._Query = rs._Query.Remove(rs._Query.Length - 1) + "))";
            return rs;
        }
        public Exp IsNull()
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += "(" + ColumnName + " IS NULL) ";
            return rs;
        }
        public Exp NotNull()
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += "(" + ColumnName + " IS NOT NULL) ";
            return rs;
        }

        public Exp Like()
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += "(" + ColumnName + " LIKE @" + ColumnName + " ) ";
            return rs;
        }

        public Exp Like(char start,String Value,char end)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query += "(" + ColumnName + " LIKE '" + start + Value + end + "' ) ";
            return rs;
        }

        public Exp AND(Exp right)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query = _Query + " AND " + right._Query;
            return rs;
        }
        public Exp OR(Exp right)
        {
            Exp rs = new Exp(ColumnName);
            rs._Query = _Query + " OR " + right._Query;
            return rs;
        }

    }
}
